跳到主要内容

Buildkit 工具

Buildkit 是一个镜像构建组件

安装使用

官方镜像:https://hub.docker.com/r/moby/buildkit

$ docker run --name buildkit -d --privileged -p 1234:1234 moby/buildkit --addr tcp://0.0.0.0:1234
$ export BUILDKIT_HOST=tcp://0.0.0.0:1234
$ docker cp buildkit:/usr/bin/buildctl /usr/local/bin/
$ buildctl build --help

构建镜像

# 本地构建
buildctl \
--addr tcp://localhost:1234 build \
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=.

# 等同于 docker build
buildctl \
--addr tcp://localhost:1234 build \
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--output type=docker,name=myimage | docker load

# push
buildctl build \
--frontend dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--output type=image,name=docker.io/username/image,push=true

参数介绍:

--local 暴露本地源文件给构建者(就是告诉 context 和 dockerfile 去哪里找),上面的 . 表示是当前目录。

--output 的 name 表示构建的镜像名称,type 表示存储的方式,更多 细节参考

在 Dockerfile 里面配置

例如需要在 Dockerfile 文件里面添加配置

# syntax = docker/dockerfile:1.3
FROM python:3.6
ADD mypackage.tgz wheels/
RUN --network=none pip install --find-links wheels mypackage

更新配置参考:

https://hub.docker.com/r/docker/dockerfile/

References